#ifndef _DAEMON_H_
#define _DAEMON_H_

#include <QObject>
#include <QTimer>

#include "file.h"
#include "folder.h"
#include "daemonerror.h"
#include "xmlerror.h"


class QString;
class QNetworkAccessManager;

namespace Tubox {

class Config;
class Disk;
class Sender;
class Receiver;
class UICommunicator;

class Daemon: public QObject {
Q_OBJECT
public:

	Daemon(const QString& configFileName) throw(DaemonError);
	~Daemon();

	bool askLogin();
	bool askLogoff();
	bool askDownload(const QString& path, const QString& name);
	bool askUpload(const QString& path, const QString& name,
								 QByteArray& file, const unsigned int version);
	bool askList(const QString& path);
	bool askMove(const QString& oldPath, const QString& oldName,
							 const QString& newPath, const QString& newName);
	bool askDelete(const QString& path, const QString& name);
	bool askMkdir(const QString& path, const QString& name);
	bool askCopy(const QString& path, const QString& name,
							 const QString& copyPath);
	bool askVersion(const QString& path, const QString& name);

	Disk* getDisk() { return disk; }

public slots:
	void slotLogin(unsigned int status);
	void slotLogoff(unsigned int status);
	void slotDownload(unsigned int status, File& file);
	void slotUpload(unsigned int status, File& file);
	void slotList(unsigned int status, const QString& path,
								QList<File> files, QList<Folder> folders);
	void slotDelete(unsigned int status,
									QString& fullPath);
	void slotVersion(unsigned int status, const File& file);
	void slotCopy(unsigned int status, QString path, const File& file);
	void slotMkdir(unsigned int status, const Folder& folder);
	void slotMove(unsigned int status, const QString& oldPath, const QString& newPath);

	void updateDisk();

signals:

private:

	QString configFileName;
	Config *config;
	Disk *disk;
	Sender *sender;
	Receiver *receiver;
	UICommunicator *uiCommunicator;
	QTimer *timer;
	bool isConnected;
};

}

#endif

